/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GenerarReciboPagoCuenta.java
 *
 * Created on Jan 3, 2012, 5:48:01 PM
 */

package INTERFAZ;

import CONTROLES.ControlCuenta;
import CONTROLES.ControlRecibo;
import CONTROLES.ControlTipoCambio;
import FACTURAS.GenerarFactura;
import MODELOS.Cliente;
import MODELOS.Cuenta;
import MODELOS.Pago;
import MODELOS.Recibo;
import MODELOS.TipoCambio;
import Reportes.Reporte;
import UTILITARIOS.Fecha;
import UTILITARIOS.Herramienta;
import UTILITARIOS.MiModelo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author VICENTE
 */
public class GenerarReciboCancelarCuenta extends javax.swing.JDialog {

    /** Creates new form GenerarReciboPagoCuenta */
    public GenerarReciboCancelarCuenta(javax.swing.JDialog parent, boolean modal, Cuenta c, String motivo, String modoPago){
        super(parent, modal);        
        initComponents();
        this.motivo = motivo;
        this.modoPago = modoPago;
        this.cuenta = c;        
        iniciarValores();
        addEventos(parent);
    }    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        pagos = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        registrar = new javax.swing.JButton();
        salir = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Datos de CIERRE DE CUENTA");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("NOMBRE CLIENTE:");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("CUENTA N#:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel4.setText("PLAN:");
        jLabel4.setName("jLabel4"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        pagos.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        pagos.setName("pagos"); // NOI18N
        jScrollPane1.setViewportView(pagos);

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel5.setText("jLabel5");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel6.setText("jLabel6");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel7.setText("jLabel7");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel8.setText("FECHA:");
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel12.setText("T.C. Compra:");
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText("6.86");
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("NFN Garantia y Cumplimiento");
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Gracias por confiar en Nosotros");
        jLabel15.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel15.setName("jLabel15"); // NOI18N

        registrar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        registrar.setText("Registrar");
        registrar.setName("registrar"); // NOI18N

        salir.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        salir.setText("Salir");
        salir.setName("salir"); // NOI18N

        jLabel16.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel16.setText("jLabel16");
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel9.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel9.setText("MONTO INVERSION:");
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel17.setFont(new java.awt.Font("Times New Roman", 0, 10));
        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel17.setText("jLabel17");
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel18.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel18.setText("NFN Inversiones");
        jLabel18.setName("jLabel18"); // NOI18N

        jLabel19.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel19.setText("DETALLE");
        jLabel19.setName("jLabel19"); // NOI18N

        jButton1.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton1.setText("Pagar e Imprimir Recibo");
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton2.setText("Pagar e Imprimir Factura");
        jButton2.setName("jButton2"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE))
                                .addGap(41, 41, 41)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                .addGap(392, 392, 392))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, 777, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(317, 317, 317)
                        .addComponent(registrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(salir))
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 777, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6))
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel17)
                    .addComponent(jLabel8)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salir)
                    .addComponent(jButton2)
                    .addComponent(registrar)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void iniciarValores(){

        this.tipoCambio = new ControlTipoCambio().dameCambio();
        totalSus = 0;
        totalBs = 0;
        Fecha fecha1 = new Fecha();
        fecha = fecha1.getFechaDate();
        String fechaText = fecha1.getFechaPrincipal();

        Cliente cliente = cuenta.getCliente();
        
        jLabel5.setText(String.valueOf(cuenta.getNumeroCuenta()));
        jLabel6.setText(cliente.getNombreCliente()+" "+cliente.getApellidosCli());
        jLabel7.setText(cuenta.getPlan().getNombrePlan());
        jLabel13.setText(String.valueOf(tipoCambio.getTipoCompra()));
        jLabel17.setText(String.valueOf(cuenta.getMonto())+" $us");        
        jLabel16.setText(fechaText);

        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.RIGHT);
        DefaultTableCellRenderer tcrc = new DefaultTableCellRenderer();
        tcrc.setHorizontalAlignment(SwingConstants.CENTER);
        double subtotalSus = 0;
        double totalRSus = 0;
        double subtotalBs = 0;
///////////////////////////////////////////////

        subtotalSus = cuenta.getMonto();        
        totalRSus = cuenta.getMonto();
        if(Bienvenida.user.getPermiso()){
/*esta afuera*/contenido_detalle = new MiModelo(new Object [][] {},new String [] {"Detalle","Monto $us", "Monto Bs","Real en $us al "+Herramienta.redondearDoubleString(cuenta.getCodigoCuenta())+" %", "Real en Bs al "+Herramienta.redondearDoubleString(cuenta.getCodigoCuenta())+" %"}, -1);
            Object [] totalCuenta = {
                "Devolucion Inversion Inicial",
                Herramienta.redondearDoubleString(subtotalSus),
                "",
                Herramienta.redondearDoubleString(totalRSus)
            };
            contenido_detalle.addRow(totalCuenta);
        } else{
/*esta afuera*/contenido_detalle = new MiModelo(new Object [][] {},new String [] {"Detalle","Monto $us", "Monto Bs"}, -1);
            Object [] totalCuenta = {
                "Devolucion Inversion Inicial",
                Herramienta.redondearDoubleString(subtotalSus),
                ""
            };
            contenido_detalle.addRow(totalCuenta);
        }
        totalSus = totalSus + subtotalSus;
  ////////////////////////////////////////////
        
        double totalRBs = 0;
        if(motivo.compareTo("CANCELADA")== 0){
            jButton1.setVisible(false);
            jButton2.setVisible(false);
            interesesPagados = cuenta.getPagosPagados();
            int numPagos = interesesPagados.size();
            if(numPagos > 0){
                for(int i=0;i<numPagos;i++){
                    subtotalSus = (interesesPagados.get(i).getMonto()*-1);
                    double subTotalRSus = cuenta.calcularMontoPago1()*-1;
                    if(Bienvenida.user.getPermiso()){
                        Object [] auxPago = {
                            "Retencion "+ interesesPagados.get(i).getNumeroPago()+"º Cuota Interes Pagada",
                            Herramienta.redondearDoubleString(subtotalSus),
                            Herramienta.redondearDoubleString(subtotalSus*tipoCambio.getTipoCompra()),
                            Herramienta.redondearDoubleString(subTotalRSus),
                            Herramienta.redondearDoubleString(subTotalRSus*tipoCambio.getTipoCompra())
                        };
                        contenido_detalle.addRow(auxPago);
                        totalRSus = totalRSus + subTotalRSus;
                    }else{
                        Object [] auxPago = {
                            "Retencion "+ interesesPagados.get(i).getNumeroPago()+"º Cuota Interes Pagada",
                            Herramienta.redondearDoubleString(subtotalSus)
                        };
                        contenido_detalle.addRow(auxPago);
                    }

                    totalSus = totalSus + subtotalSus;
                }
            }
            if(Bienvenida.user.getPermiso()){
                Object [] auxPago = {
                    "TOTAL A PAGAR =>",
                    Herramienta.redondearDoubleString(totalSus),
                    "",
                    Herramienta.redondearDoubleString(totalRSus),
                    ""
                };
                contenido_detalle.addRow(auxPago);
                pagos.setModel(contenido_detalle);
                pagos.getColumnModel().getColumn(3).setCellRenderer(tcr);
                pagos.getColumnModel().getColumn(4).setCellRenderer(tcr);
                pagos.getColumnModel().getColumn(3).setMaxWidth(130);
                pagos.getColumnModel().getColumn(4).setMaxWidth(130);
                pagos.getColumnModel().getColumn(3).setMinWidth(130);
                pagos.getColumnModel().getColumn(4).setMinWidth(130);
            }else{
                Object [] auxPago = {
                    "TOTAL A PAGAR =>",
                    Herramienta.redondearDoubleString(totalSus),
                    ""
                };
                contenido_detalle.addRow(auxPago);
                pagos.setModel(contenido_detalle);
            }
            
        }else{
            registrar.setVisible(false);
            interesesPagados = cuenta.getPagosDisponibles();
            int numPagos = interesesPagados.size();
            detalle = "";
            if(numPagos > 0){                
                totalRBs = cuenta.calcularMontoPago1() * tipoCambio.getTipoCompra();
                for(int i=0;i<numPagos;i++){
                    subtotalBs = (interesesPagados.get(i).getMonto()*tipoCambio.getTipoCompra());
                    String d = "Pago "+ interesesPagados.get(i).getNumeroPago()+"º Cuota Interes TOTAL = "+Herramienta.redondearDoubleString(subtotalBs);
                    if(Bienvenida.user.getPermiso()){
                        Object [] auxPago = {
                            d,
                            interesesPagados.get(i).getMonto(),
                            Herramienta.redondearDoubleString(subtotalBs),
                            Herramienta.redondearDoubleString(cuenta.calcularMontoPago1()),
                            Herramienta.redondearDoubleString(totalRBs)
                        };
                        contenido_detalle.addRow(auxPago);                        
                    }else{
                        Object [] auxPago = {
                            d,
                            interesesPagados.get(i).getMonto(),
                            Herramienta.redondearDoubleString(subtotalBs),
                        };
                        contenido_detalle.addRow(auxPago); 
                    }
                    totalBs = totalBs + subtotalBs;
                    detalle = detalle+d+"\n";
                }
                totalRBs = totalRBs * numPagos;
            }
            if(Bienvenida.user.getPermiso()){
                Object [] auxPago = {
                    "TOTAL A PAGAR =>",
                    "",
                    Herramienta.redondearDoubleString(totalBs),
                    "",
                    Herramienta.redondearDoubleString(totalRBs)
                };
                contenido_detalle.addRow(auxPago);
                pagos.setModel(contenido_detalle);
                pagos.getColumnModel().getColumn(3).setCellRenderer(tcr);
                pagos.getColumnModel().getColumn(4).setCellRenderer(tcr);
                pagos.getColumnModel().getColumn(3).setMaxWidth(130);
                pagos.getColumnModel().getColumn(4).setMaxWidth(130);
                pagos.getColumnModel().getColumn(3).setMinWidth(130);
                pagos.getColumnModel().getColumn(4).setMinWidth(130);
            }else{
                Object [] auxPago = {
                    "TOTAL A PAGAR =>",
                    "",
                    Herramienta.redondearDoubleString(totalBs)
                };
                contenido_detalle.addRow(auxPago);
                pagos.setModel(contenido_detalle);
            }
        }
//        String valSus = totalSus+"";
//        String valBs = totalBs+"";
//        BigDecimal big = new BigDecimal(valSus);
//        totalSus = big.setScale(3, RoundingMode.HALF_UP).doubleValue();
//
//        BigDecimal big1 = new BigDecimal(valBs);
//        totalBs = big1.setScale(3, RoundingMode.HALF_UP).doubleValue();

        pagos.getColumnModel().getColumn(0).setCellRenderer(tcrc);
        pagos.getColumnModel().getColumn(1).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(2).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(1).setMinWidth(80);
        pagos.getColumnModel().getColumn(1).setMaxWidth(80);
        pagos.getColumnModel().getColumn(2).setMinWidth(80);
        pagos.getColumnModel().getColumn(2).setMaxWidth(80);
    }
    private void addEventos(final javax.swing.JDialog padre){

        registrar.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                if(motivo.compareTo("CANCELADA")== 0){
                    if(new ControlCuenta().registrarCancelarCuenta(cuenta)== true)//registrar el recibo el la base de datos
                    {
                        JOptionPane.showMessageDialog(null, "La CUENTA ha sido CANCELADA Correctamente\n", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
                        dispose();
                    }else
                        JOptionPane.showMessageDialog(null, "No se ha podido CANCELAR la cuenta Comuniquese Con el Soporte Tecnico para Solucionar el Problema", "Confirmación", JOptionPane.ERROR_MESSAGE);
                        
                }
            }
        });
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                    ControlRecibo control_recibo = new ControlRecibo();
                    Recibo recibo = new Recibo();
                    recibo.setFecha(fecha);
                    recibo.setMonto(totalBs);
                    recibo.setTipoCambio(tipoCambio.getTipoCompra());
                    recibo.setIdSucursal(Bienvenida.sucursal.getIdSucursal());
                    recibo.setIdUsuario(Bienvenida.user.getIdUsuario());

                    recibo = control_recibo.registrarReciboCuenta(recibo, cuenta, motivo, modoPago);
                    if(recibo != null)//registrar el recibo el la base de datos
                    {
                        JOptionPane.showMessageDialog(null, "La CUENTA ha sido cerrada Correctamente\n prepare la impresora para imprimir el recibo Por sus intereses PENDIENTES", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
                        dispose();
                        Reporte r = new Reporte();
                r.ejecutarRecibo(recibo,detalle,cuenta);
                    }else
                        JOptionPane.showMessageDialog(null, "No se ha podido cerrar la cuenta Comuniquese Con el Soporte Tecnico para Solucionar el Problema", "Confirmación", JOptionPane.ERROR_MESSAGE);
            }
        });
        jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                    Recibo recibo = guardar();
                if( recibo != null){
                    JOptionPane.showMessageDialog(null, "Se ha registrado el pago CORRECTAMENTE \n pulse ACEPTAR y se imprimira La Factura", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
                    //imprimir
                    dispose();
                    GenerarFactura factura = new GenerarFactura(null, true, interesesPagados);
                    Herramienta.centerOnScreen(factura);
                    factura.setVisible(true);
                }
            }
        });

        salir.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int res = JOptionPane.showConfirmDialog(null, "Si cierra la ventana no se registrara el pago.\n Seguro que quiere cerrar la ventana?", "Advertencia", JOptionPane.OK_CANCEL_OPTION);
                if(res ==0){
                    dispose();
                    padre.setVisible(true);
                }
            }
        });
        addWindowListener( new WindowAdapter(){
                @Override
                public void windowClosing(WindowEvent e) {
                        int res = JOptionPane.showConfirmDialog(null, "Si cierra la ventana no se registrara el pago.\n Seguro que quiere cerrar la ventana?", "Advertencia", JOptionPane.OK_CANCEL_OPTION);
                        if(res ==0){
                            dispose();
                            padre.setVisible(true);
                        }
                }
        });
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable pagos;
    private javax.swing.JButton registrar;
    private javax.swing.JButton salir;
    // End of variables declaration//GEN-END:variables

    private MiModelo contenido_detalle;
    private Cuenta cuenta;
    private ArrayList<Pago> interesesPagados;
    private double totalSus;
    private double totalBs;
    private String detalle;
    private Date fecha;    
    private TipoCambio tipoCambio;
    private String motivo;
    private String modoPago;

    public Recibo guardar(){
        ControlRecibo control_recibo = new ControlRecibo();
        Recibo recibo = new Recibo();
        recibo.setFecha(fecha);
        recibo.setMonto(totalBs);
        recibo.setTipoCambio(tipoCambio.getTipoCompra());
        recibo.setIdSucursal(Bienvenida.sucursal.getIdSucursal());
        recibo.setIdUsuario(Bienvenida.user.getIdUsuario());
        return  control_recibo.registrarReciboCuenta(recibo, cuenta, "CERRADA",modoPago);//registrar el recibo el la base de datos
   }
}

